package cn.e4j.modular.system.controller;

import cn.e4j.core.base.controller.BaseController;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.PageReData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.modular.system.entity.SysLoadlog;
import cn.e4j.modular.system.entity.SysLoadlogError;
import cn.e4j.modular.system.entity.SysTask;
import cn.e4j.modular.system.service.SysLoadlogService;
import cn.e4j.modular.system.service.SysTaskService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
 * Load日志控制类
 *
 * @author yuan_rz
 * @Date 2019/03/12 14:45
 */
@Controller
@RequestMapping("/sys/loadlog")
public class SysLoadlogController extends BaseController {

    @Autowired
    private SysLoadlogService sysLoadlogService;

    /**
     * 跳转页面
     */
    @RequiresPermissions("sys:loadlog:init")
    @RequestMapping(value = {"", "init"})
    public String index() {
        return "/pc/system/loadlog.html";
    }

    /**
     * 查询列表数据
     */
    @RequestMapping("/getListData")
    @RequiresPermissions("sys:loadlog:init")
    @ResponseBody
    public ResponseData getListData(@DtoParam DtoWapper dtoWapper) {
        Page<Object> page = dtoWapper.getPage();
        Dto inDto = dtoWapper.getDto();
        List<SysLoadlog> result = sysLoadlogService.getListData(page, inDto);
        return new PageReData(page, result);
    }

    /**
     * 查询列表数据详细
     */
    @RequestMapping("/getListDataDetail")
    @RequiresPermissions("sys:loadlog:init")
    @ResponseBody
    public ResponseData getListDataDetail(@DtoParam DtoWapper dtoWapper) {
        Page<Object> page = dtoWapper.getPage();
        Dto inDto = dtoWapper.getDto();
        List<SysLoadlogError> result = sysLoadlogService.getListDataDetail(page, inDto);
        return new PageReData(page, result);
    }
    
    /**
     * 删除数据
     */
    @RequestMapping("/deleteData")
    @RequiresPermissions("sys:loadlog:init")
    @ResponseBody
    public ResponseData deleteData(SysLoadlog sysLoadlog) {
        sysLoadlogService.deleteData(sysLoadlog);
        return SUCCESS_TIP;
    }

    /**
     * 批量删除数据
     */
    @RequestMapping("/deleteDataBatch")
    @RequiresPermissions("sys:loadlog:init")
    @ResponseBody
    public ResponseData deleteDataBatch(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<SysLoadlog> sysLoadlogList = inDto.getReqList(SysLoadlog.class);
        sysLoadlogService.deleteDataBatch(sysLoadlogList);
        return SUCCESS_TIP;
    }

    /**
     * 清空数据
     */
    @RequestMapping("/deleteDataAll")
    @RequiresPermissions("sys:loadlog:init")
    @ResponseBody
    public ResponseData deleteDataAll() {
        sysLoadlogService.deleteDataAll();
        return SUCCESS_TIP;
    }
}
